package com.ruoyi.traces.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.traces.domain.TraceUserProduct;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.traces.domain.TraceUserMaterial;
import com.ruoyi.traces.service.ITraceUserMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-02-09
 */
@RestController
@RequestMapping("/trace/user/material")
public class TraceUserMaterialController extends BaseController
{
    @Autowired
    private ITraceUserMaterialService traceUserMaterialService;

    /**
     * 查询用户产品总数
     */
    @GetMapping("/count")
    public int count()
    {
        List<TraceUserMaterial> list = new ArrayList<TraceUserMaterial>();
        TraceUserMaterial traceUserMaterial = new TraceUserMaterial();
        list = traceUserMaterialService.selectTraceUserMaterialList(traceUserMaterial);
        return list.size();
    }
    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TraceUserMaterial traceUserMaterial)
    {
        startPage();
        List<TraceUserMaterial> list = traceUserMaterialService.selectTraceUserMaterialList(traceUserMaterial);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:material:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceUserMaterial traceUserMaterial)
    {
        List<TraceUserMaterial> list = traceUserMaterialService.selectTraceUserMaterialList(traceUserMaterial);
        ExcelUtil<TraceUserMaterial> util = new ExcelUtil<TraceUserMaterial>(TraceUserMaterial.class);
        return util.exportExcel(list, "material");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(traceUserMaterialService.selectTraceUserMaterialById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TraceUserMaterial traceUserMaterial)
    {
        traceUserMaterial.setUsername(SecurityUtils.getUsername());
        return toAjax(traceUserMaterialService.insertTraceUserMaterial(traceUserMaterial));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:material:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TraceUserMaterial traceUserMaterial)
    {
        return toAjax(traceUserMaterialService.updateTraceUserMaterial(traceUserMaterial));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:material:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(traceUserMaterialService.deleteTraceUserMaterialByIds(ids));
    }
}
